/*
 * @Author: new-wang
 * @Date: 2025-08-21 14:30:40
 * @LastEditors: new-wang
 * @LastEditTime: 2025-08-28 17:09:58
 * @FilePath: \nest-demo\src\module\system\auth\dto\index.ts
 * @Description: 权限认证 - 包括登录、登出、注册、鉴权等 参数验证
 */

import { ApiProperty } from '@nestjs/swagger'
import {
  IsString,
  MaxLength,
  MinLength,
  IsBoolean,
  IsNotEmpty,
  IsOptional,
} from 'class-validator'
import { Transform } from 'class-transformer'

export class RegisterDto {
  @ApiProperty({
    description: '用户名',
    example: 'admin',
    required: true,
  })
  @IsNotEmpty({ message: '用户名不能为空' })
  @IsString()
  @MaxLength(10, { message: '用户名不可超过10位' })
  username: string

  @ApiProperty({
    description: '密码',
    required: true,
  })
  @IsNotEmpty({ message: '密码不能为空' })
  @IsString()
  @MinLength(5, { message: '密码长度不可少于5位' })
  @MaxLength(20, { message: '密码长度不可超过20位' })
  password: string

  @ApiProperty({
    description: '记住我',
    // example: true,
    required: false,
  })
  @IsOptional()
  @Transform(({ value }) =>
    value === 'true' || value === true
      ? true
      : value === 'false' || value === false
        ? false
        : value,
  )
  @IsBoolean()
  remember?: boolean

  @ApiProperty({
    description: '确认密码',
    required: false,
  })
  @IsOptional()
  @IsString()
  confirmPassword?: string

  @ApiProperty({
    description: '验证码',
    required: false,
  })
  @IsOptional()
  @IsString()
  code: string

  /**
   * 系统标识
   * 用于区分不同的系统或应用 对应系统表 code/id
   */
  @ApiProperty({
    description: '系统标识',
    required: false,
  })
  @IsOptional()
  @IsString()
  systemCode?: string

  /**
   * 角色标识
   * 用于区分不同的角色或权限 对应角色表 name/id
   */
  @ApiProperty({
    description: '角色标识',
    required: false,
  })
  @IsOptional()
  @IsString()
  roleCode?: string
}

// export class RegisterDto extends LoginDto {}

export class LoginDto {
  @ApiProperty({
    description: '用户名 - 统一接收用户名/邮箱/手机号',
    example: 'admin',
    required: true,
  })
  @IsNotEmpty({ message: '用户名不能为空' })
  @IsString()
  @MaxLength(10, { message: '用户名不可超过10位' })
  account: string

  @ApiProperty({
    description: '密码',
    required: true,
  })
  @IsNotEmpty({ message: '密码不能为空' })
  @IsString()
  @MinLength(5, { message: '密码长度不可少于5位' })
  @MaxLength(20, { message: '密码长度不可超过20位' })
  password: string

  @ApiProperty({
    description: '记住我',
    // example: true,
    required: false,
  })
  @IsOptional()
  @Transform(({ value }) =>
    value === 'true' || value === true
      ? true
      : value === 'false' || value === false
        ? false
        : value,
  )
  @IsBoolean()
  remember?: boolean

  @ApiProperty({
    description: '验证码',
    required: false,
  })
  @IsOptional()
  @IsString()
  code: string

  /**
   * 系统标识
   * 用于区分不同的系统或应用 对应系统表 code/id
   */
  @ApiProperty({
    description: '系统标识',
    required: false,
  })
  @IsOptional()
  @IsString()
  systemCode?: string
}
